<template>
    <div class="top-movers">
        <div class="header">
            <div class="title">Top Movers</div>
            <div class="select-box">
                <div class="active-item">
                    <div class="icon" style="--icon: url(/language/lang/en.png)"></div>
                    <div class="text">USA</div>
                </div>
            </div>
        </div>
        <div class="stock-list">
            <div class="stock-item" v-for="item in stock_list" :key="item.id" @click="jumpToTabbarTrade(item)">
                <div class="main">
                    <div class="left-box">
                        <div class="header-box">
                            <div class="symbol">{{ item.symbol }}</div>
                            <div class="name">{{ item.name }}</div>
                        </div>
                        <div class="center">
                            <div class="price">{{ item.price }}</div>
                            <div class="change" :style="`color: ${ parseFloat(item.change) >= 0 ? 'var(--positive-number-color)' : 'var(--negative-number-color)' }`">{{ item.change_price }} {{ item.change }}</div>
                        </div>
                    </div>
                    <div class="right-box">
                        <div class="icon" :style="`--icon: url(${ item.svg })`"></div>
                        <div class="btn">Trade</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { stock_list, changeStock, openStockDetail, jumpToTabbarTrade } from '@/service/market.js';
import { active_stock } from '@/service/trading.js';
import { routerTo } from '@/utils/jump';
</script>

<style scoped lang="less">
.top-movers {
    display: flex;
    flex-direction: column;
    gap: 1vw;

    .header {
        width: 100%;
        height: 8vw;
        display: flex;
        justify-content: space-between;
        align-items: center;
    
        .title {
            font-size: 4vw;
            font-weight: 700;
        }

        .select-box {
            box-sizing: border-box;
            width: 25vw;
            height: 8vw;
            display: flex;
            align-items: center;
            padding: 1vw 2vw;
            border-radius: 2vw;
            background-color: #fff;
            box-shadow: 0 0 5vw rgba(0, 0, 0, 0.05);

            .active-item {
                width: 100%;
                display: flex;
                justify-content: space-between;
                align-items: center;

                .icon {
                    --size: 5vw;
                    --w: var(--size);
                    --h: var(--size);
                }

                .text {
                    font-size: 3vw;
                }
            }
        }
    }

    .stock-list {
        display: flex;
        flex-direction: column;
        gap: 2.5vw;

        .stock-item {
            box-sizing: border-box;
            width: 100%;
            padding: 3vw;
            background-color: #fff;
            box-shadow: 0 0 1.5vw rgba(0, 0, 0, 0.1);
            border-radius: 2vw;
            display: flex;
            flex-direction: column;
            gap: 2vw;

            .main {
                display: flex;
                justify-content: space-between;
            }

            .left-box {
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                gap: 3vw;

                .header-box {
                    .symbol {
                        font-size: 3.5vw;
                        font-weight: 500;
                    }
    
                    .name {
                        font-size: 3vw;
                        color: var(--text-light-color);
                    }
                }
                
                .center {
                    .price {
                        font-size: 4vw;
                        font-weight: 500;
                    }
    
                    .change {
                        font-size: 3vw;
                    }
                }
            }

            .right-box {
                --w: 30vw;
                --h: 15vw;
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                gap: 3vw;

                .icon {
                    background-size: cover;
                }

                .btn {
                    box-sizing: border-box;
                    width: 30vw;
                    padding: 1vw 2vw;
                    color: #fff;
                    font-size: 3vw;
                    text-align: center;
                    border-radius: 1.5vw;
                    background-color: var(--active-color);
                }
            }

            .footer {
                display: flex;
                justify-content: space-between;

                &>div {
                    font-size: 2.5vw;
                    color: var(--text-light-color);
                }
            }

            .btn-box {
                display: flex;
                gap: 2vw;

                .btn {
                    flex: 1;
                    height: 7vw;
                    border-radius: 1.5vw;
                    display: flex;
                    justify-content: center;
                    align-items: center;

                    &>div {
                        font-size: 3vw;
                        font-weight: 600;
                        color: #fff;
                    }
                }

                .buy-btn {
                    background-color: var(--positive-number-color);
                }

                .sell-btn {
                    background-color: var(--negative-number-color);
                }
            }
        }
    }
}
</style>